package com.ruoyi.project.system.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.domain.SysUserProductPrice;
import com.ruoyi.project.system.service.ISysUserProductPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户产品定价Controller
 * 
 * @author ruoyi
 * @date 2024-07-23
 */
@RestController
@RequestMapping("/price")
public class SysUserProductPriceController extends BaseController
{
    @Autowired
    private ISysUserProductPriceService sysUserProductPriceService;

    /**
     * 查询用户产品定价列表
     */
    @PreAuthorize("@ss.hasPermi('system:price:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysUserProductPrice sysUserProductPrice)
    {
        startPage();
        List<SysUserProductPrice> list = sysUserProductPriceService.selectSysUserProductPriceList(sysUserProductPrice);
        return getDataTable(list);
    }

    /**
     * 导出用户产品定价列表
     */
    @PreAuthorize("@ss.hasPermi('system:price:export')")
    @Log(title = "用户产品定价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysUserProductPrice sysUserProductPrice)
    {
        List<SysUserProductPrice> list = sysUserProductPriceService.selectSysUserProductPriceList(sysUserProductPrice);
        ExcelUtil<SysUserProductPrice> util = new ExcelUtil<SysUserProductPrice>(SysUserProductPrice.class);
        util.exportExcel(response, list, "用户产品定价数据");
    }

    /**
     * 新增用户产品定价
     */
    @PreAuthorize("@ss.hasPermi('system:price:add')")
    @Log(title = "用户产品定价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysUserProductPrice sysUserProductPrice)
    {
        return toAjax(sysUserProductPriceService.insertSysUserProductPrice(sysUserProductPrice));
    }

    /**
     * 修改用户产品定价
     */
//    @PreAuthorize("@ss.hasPermi('system:price:edit')")
    @Log(title = "用户产品定价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysUserProductPrice sysUserProductPrice)
    {
        return toAjax(sysUserProductPriceService.updateSysUserProductPrice(sysUserProductPrice));
    }


    /**
     * 删除用户产品定价
     */
    @PreAuthorize("@ss.hasPermi('system:price:remove')")
    @Log(title = "用户产品定价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysUserProductPriceService.deleteSysUserProductPriceByIds(ids));
    }
}
